<?php
namespace app\controller\handler;
use app\controller\Common;
use think\Db;
use think\Model;

class Blog extends Common{

  public function getResumeList(){
    $uid = model('User')::getCurrentUid();
    $res1 = Db::query("select * from `#__blog_skill` where uid=$uid and status=1 order by skill_type asc,sort asc");
    $res2 = Db::query("select * from `#__blog_experience` where uid=$uid and status=1 order by sort asc");
    $res3 = Db::query("select * from `#__blog_education` where uid=$uid and status=1 order by sort asc");
    if($res1 || $res2 || $res3){
      $result['ret'] = 1;
      $result['skill'] = $res1;
      $result['experience'] = $res2;
      $result['education'] = $res3;
    }else{
      $result['ret'] = 0;
      $result['msg'] = '未查询到数据';
    }
    return $result;
  }

  public function addEvent(){
    $base = input('post.')['base'];
    $base['ctime'] = time();
    $res = model('Event')::create($base);
    if($res){
      $result['ret'] = 1;
      $result['msg'] = '添加成功';
    }else{
      $result['ret'] = 0;
      $result['msg'] = '添加失败';
    }
    return $result;
  }

  public function getEventDetailById(){
    $wh['id'] = input('post.')['id'];
    $wh['status'] = 1;
    $res = model('Event')::get($wh);
    if($res){
      $result['ret'] = 1;
      $result['data'] = $res;
    }else{
      $result['ret'] = 0;
      $result['msg'] = '未查询到数据';
    }
    return $result;
  }

  public function editEvent(){
    $base = input('post.')['base'];
    $wh['id'] = input('post.')['id'];
    $res = model('Event')::where($wh)->update($base);
    if($res){
      $result['ret'] = 1;
      $result['msg'] = '编辑成功';
    }else{
      $result['ret'] = 0;
      $result['msg'] = '编辑失败';
    }
    return $result;
  }

  public function deleteEvent(){
    $wh['id'] = input('post.')['id'];
    $up['status'] = 0;
    $res = model('Event')::where($wh)->update($up);
    if($res){
      $result['ret'] = 1;
      $result['msg'] = '删除成功';
    }else{
      $result['ret'] = 0;
      $result['msg'] = '删除失败';
    }
    return $result;
  }



}//END